-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature flag status request [IDE-171] (#454)
- Loading branch information
Cata
authored
Mar 11, 2024
1 parent
0823cf0
commit 888780b
Showing
5 changed files
with
268 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* © 2023 Snyk Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package command | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/snyk/snyk-ls/application/config" | ||
"github.com/snyk/snyk-ls/domain/snyk" | ||
"github.com/snyk/snyk-ls/infrastructure/snyk_api" | ||
) | ||
|
||
type featureFlagStatus struct { | ||
command snyk.CommandData | ||
apiClient snyk_api.SnykApiClient | ||
} | ||
|
||
func (cmd *featureFlagStatus) Command() snyk.CommandData { | ||
return cmd.command | ||
} | ||
|
||
func (cmd *featureFlagStatus) Execute(ctx context.Context) (any, error) { | ||
if config.CurrentConfig().Token() == "" { | ||
return nil, nil | ||
} | ||
|
||
args := cmd.command.Arguments | ||
if len(args) < 1 { | ||
return nil, nil | ||
} | ||
|
||
ff := args[0].(snyk_api.FeatureFlagType) | ||
featureFlagResponse, err := cmd.apiClient.FeatureFlagSettings(ff) | ||
return featureFlagResponse, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* © 2023 Snyk Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package command | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/snyk/snyk-ls/domain/snyk" | ||
"github.com/snyk/snyk-ls/infrastructure/snyk_api" | ||
"github.com/snyk/snyk-ls/internal/testutil" | ||
) | ||
|
||
func Test_ApiClient_FeatureFlagIsEnabled(t *testing.T) { | ||
testutil.UnitTest(t) | ||
|
||
// Arrange | ||
var featureFlagType snyk_api.FeatureFlagType = "snykCodeConsistentIgnores" | ||
expectedResponse := snyk_api.FFResponse{Ok: true} | ||
|
||
fakeApiClient := &snyk_api.FakeApiClient{} | ||
fakeApiClient.SetResponse("FeatureFlagSettings", expectedResponse) | ||
|
||
// Pass the featureFlagType to the command | ||
featureFlagStatusCmd := featureFlagStatus{ | ||
apiClient: fakeApiClient, | ||
command: snyk.CommandData{Arguments: []interface{}{featureFlagType}}, | ||
} | ||
|
||
// Execute the command | ||
result, err := featureFlagStatusCmd.Execute(context.Background()) | ||
|
||
// Assert | ||
assert.NoError(t, err) | ||
ffResponse, ok := result.(snyk_api.FFResponse) | ||
assert.True(t, ok) | ||
assert.True(t, ffResponse.Ok) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters