Skip to content

Commit

Permalink
fix: fixed check on project ExternalOAuth setting
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Nov 15, 2023
1 parent 403f26e commit de67ce6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changes/unreleased/Fixed-20231115-124951.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Fixed
body: fixed check on project ExternalOAuth setting when processing state and plan
differences
time: 2023-11-15T12:49:51.714555603+01:00
4 changes: 2 additions & 2 deletions internal/resources/project/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewProjectFromNative(n *platform.Project) Project {
}

func (p *Project) setStateData(o Project) {
if len(p.ExternalOAuth) > 0 {
if len(p.ExternalOAuth) > 0 && len(o.ExternalOAuth) > 0 {
p.ExternalOAuth[0].AuthorizationHeader = o.ExternalOAuth[0].AuthorizationHeader
}

Expand All @@ -139,7 +139,7 @@ func (p *Project) setStateData(o Project) {
}
}

func (p Project) updateActions(plan Project) platform.ProjectUpdate {
func (p *Project) updateActions(plan Project) platform.ProjectUpdate {
result := platform.ProjectUpdate{
Version: int(p.Version.ValueInt64()),
Actions: []platform.ProjectUpdateAction{},
Expand Down
72 changes: 72 additions & 0 deletions internal/resources/project/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,75 @@ func TestUpdateActions(t *testing.T) {
})
}
}

func TestSetStateData(t *testing.T) {
tests := []struct {
name string
state Project
plan Project
expected Project
}{
{
name: "externalOAuth nil",
state: Project{
ExternalOAuth: nil,
Carts: []Carts{
{},
},
},
plan: Project{
ExternalOAuth: nil,
},
expected: Project{
ExternalOAuth: nil,
Carts: nil,
},
}, {
name: "externalOAuth in state",
state: Project{
ExternalOAuth: []ExternalOAuth{
{AuthorizationHeader: types.StringValue("some-value")},
},
Carts: []Carts{
{},
},
},
plan: Project{
ExternalOAuth: nil,
},
expected: Project{
ExternalOAuth: []ExternalOAuth{
{AuthorizationHeader: types.StringValue("some-value")},
},
Carts: nil,
},
}, {
name: "externalOAuth in plan",
state: Project{
ExternalOAuth: []ExternalOAuth{
{AuthorizationHeader: types.StringValue("some-value")},
},
Carts: []Carts{
{},
},
},
plan: Project{
ExternalOAuth: []ExternalOAuth{
{AuthorizationHeader: types.StringValue("some-other-value")},
},
},
expected: Project{
ExternalOAuth: []ExternalOAuth{
{AuthorizationHeader: types.StringValue("some-other-value")},
},
Carts: nil,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.state.setStateData(tt.plan)
assert.Equal(t, tt.expected, tt.state)
})
}
}

0 comments on commit de67ce6

Please sign in to comment.