Skip to content

Commit

Permalink
InspectOutput ProjectID and TestName unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov authored and yorugac committed Feb 26, 2024
1 parent 2fa5d6d commit df39311
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions pkg/cloud/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cloud

import (
"encoding/json"
"testing"
)

func TestInspectOutput_TestNameAndProjectID(t *testing.T) {
t.Parallel()

tests := []struct {
name string
fields []byte
expectedProjectID int64
expectedName string
}{
{
name: "empty",
fields: []byte(`{}`),
expectedProjectID: 0,
},
{
name: "only legacy way of defining the options",
fields: []byte(`{"ext":{"loadimpact":{"name":"test","projectID":123}}}`),
expectedProjectID: 123,
expectedName: "test",
},
{
name: "only new way of defining the options",
fields: []byte(`{"cloud":{"name":"lorem","projectID":321}}`),
expectedProjectID: 321,
expectedName: "lorem",
},
{
name: "both way, priority to new way",
fields: []byte(`{"cloud":{"name":"ipsum","projectID":987},"ext":{"loadimpact":{"name":"test","projectID":123}}}`),
expectedProjectID: 987,
expectedName: "ipsum",
},
}
for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var io *InspectOutput
if err := json.Unmarshal(tt.fields, &io); err != nil {
t.Errorf("error unmarshalling json: %v", err)
}

if got := io.ProjectID(); got != tt.expectedProjectID {
t.Errorf("InspectOutput.ProjectID() = %v, want %v", got, tt.expectedProjectID)
}

if got := io.TestName(); got != tt.expectedName {
t.Errorf("InspectOutput.TestName() = %v, want %v", got, tt.expectedName)
}
})
}
}

func TestInspectOutput_SetTestName(t *testing.T) {
t.Parallel()

io := &InspectOutput{}
if got := io.TestName(); got != "" {
t.Errorf("InspectOutput.TestName() = %v, want empty name", got)
}

io.SetTestName("test-lore-ipsum")
if got := io.TestName(); got != "test-lore-ipsum" {
t.Errorf("InspectOutput.TestName() = %v, want test-lore-ipsum", got)
}
}

0 comments on commit df39311

Please sign in to comment.