run TestSetLanguage with execPath instead of input

This commit is contained in:
Alfred Kamanda 2024-09-17 18:54:07 +03:00
parent 2e7c07e6f4
commit 75ab9c66a3
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -539,63 +539,55 @@ func TestSetLanguage(t *testing.T) {
// Define test cases // Define test cases
tests := []struct { tests := []struct {
name string name string
input []byte execPath []string
expectedFlags []uint32
expectedResult resource.Result expectedResult resource.Result
flagManagerResponse uint32
flagManagerError error
}{ }{
{ {
name: "English language", name: "Set Default Language (English)",
input: []byte("0"), execPath: []string{"set_default"},
expectedFlags: []uint32{state.FLAG_LANG, 123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{state.FLAG_LANG, 8}, FlagSet: []uint32{state.FLAG_LANG, 8},
Content: "eng", Content: "eng",
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
{ {
name: "Swahili language", name: "Set Swahili Language",
input: []byte("1"), execPath: []string{"set_swa"},
expectedFlags: []uint32{state.FLAG_LANG, 123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{state.FLAG_LANG, 8}, FlagSet: []uint32{state.FLAG_LANG, 8},
Content: "swa", Content: "swa",
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
{ {
name: "Unhandled Input", name: "Unhandled path",
input: []byte("3"), execPath: []string{""},
expectedFlags: []uint32{123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{8}, FlagSet: []uint32{8},
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mockState := state.NewState(16)
// Set the ExecPath
mockState.ExecPath = tt.execPath
// Create the Handlers instance with the mock flag manager // Create the Handlers instance with the mock flag manager
h := &Handlers{ h := &Handlers{
flagManager: fm.parser, flagManager: fm.parser,
st: mockState,
} }
// Call the method // Call the method
res, err := h.SetLanguage(context.Background(), "set_language", tt.input) res, err := h.SetLanguage(context.Background(), "set_language", nil)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
// Assert that the Result FlagSet has the required flags after language switch // Assert that the Result FlagSet has the required flags after language switch
assert.Equal(t, res, tt.expectedResult, "Flags should be equal to account created") assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
}) })
} }