Skip to content

Commit

Permalink
Adding tests to verify trie's functionalities, testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Aug 13, 2023
1 parent a137b34 commit a11245a
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions tests/env_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,68 @@ type EnvData struct {
}

func TestL2EnvCommand(t *testing.T) {
cmdArgs := []string{"-e", "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"}
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)
// Check the "AHOST" key

// Check the "AHOST" key is present
checkAHost(t, envMap)

// Check the "BHOST" key
checkBHost(t, envMap)
}

func TestL2EnvForAHOenv(t *testing.T) {
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=A", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)

// Check the "AHOST" key is present
checkAHost(t, envMap)

// Check the "BHOST" key is absent
checkBHostDoesNotExist(t, envMap)
}

func TestL2EnvForBHOenv(t *testing.T) {
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=B", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)

// Check the "BHOST" key is present
checkBHost(t, envMap)

// Check the "AHOST" key is absent
checkAHostDoesNotExist(t, envMap)
}

func TestL2EnvCommandVerbose(t *testing.T) {
cmdArgs := []string{"-ev", "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"}
fpath := "../elfparser/ElfTestSuite/root_variable_override/api/y_0020_root_override.l2"
cmdArgs := []string{"-e=", "-v", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)
// Check the "AHOST" key

// Check the "AHOST" key is present
checkAHost(t, envMap)

// Check the "BHOST" key
// Check the "BHOST" key is present
checkBHost(t, envMap)
}

func TestL2EnvWithoutL2config(t *testing.T) {
cmdArgs := []string{"-ev", "../elfparser/ElfTestSuite/no_l2config/api/y_0021_no_l2config.l2"}
fpath := "../elfparser/ElfTestSuite/no_l2config/api/y_0021_no_l2config.l2"
cmdArgs := []string{"-e=", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)
// Check the "AHOST" key

// Check the "AHOST" key is present
checkAHost(t, envMap)
}

func TestL2EnvWithoutL2env(t *testing.T) {
cmdArgs := []string{"-ev", "../elfparser/ElfTestSuite/no_l2env/api/y_0022_no_l2env.l2"}
fpath := "../elfparser/ElfTestSuite/no_l2env/api/y_0022_no_l2env.l2"
cmdArgs := []string{"-e=", fpath}
envMap := runL2CommandAndParseJSON(t, cmdArgs...)

// Check the "BHOST" key
// Check the "BHOST" key is present
checkBHost(t, envMap)
}

Expand Down Expand Up @@ -130,3 +161,15 @@ func checkBHost(t *testing.T, envMap map[string]EnvData) {
}
}
}

func checkBHostDoesNotExist(t *testing.T, envMap map[string]EnvData) {
if _, ok := envMap["BHOST"]; ok {
t.Error("Expected 'BHOST' key not to be present in the JSON, but it was found")
}
}

func checkAHostDoesNotExist(t *testing.T, envMap map[string]EnvData) {
if _, ok := envMap["AHOST"]; ok {
t.Error("Expected 'AHOST' key not to be present in the JSON, but it was found")
}
}

0 comments on commit a11245a

Please sign in to comment.