-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix --from-dir flag init Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix env var not set for k8s tests also Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix k8s test Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * address review comments Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * fix typo Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * addressed comments Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> * Update tests/e2e/common/common.go Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Shubham Sharma <shubhash@microsoft.com> * fix typo Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Shubham Sharma <shubhash@microsoft.com>
- Loading branch information
1 parent
1331e29
commit 5879d91
Showing
9 changed files
with
372 additions
and
120 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
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,64 @@ | ||
/* | ||
Copyright 2021 The Dapr Authors | ||
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 standalone | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
const bundleDetailsFileName = "details.json" | ||
|
||
type bundleDetails struct { | ||
RuntimeVersion *string `json:"daprd"` | ||
DashboardVersion *string `json:"dashboard"` | ||
CLIVersion *string `json:"cli"` | ||
BinarySubDir *string `json:"daprBinarySubDir"` | ||
ImageSubDir *string `json:"dockerImageSubDir"` | ||
DaprImageName *string `json:"daprImageName"` | ||
DaprImageFileName *string `json:"daprImageFileName"` | ||
} | ||
|
||
// readAndParseDetails reads the file in detailsFilePath and tries to parse it into the bundleDetails struct. | ||
func (b *bundleDetails) readAndParseDetails(detailsFilePath string) error { | ||
bytes, err := ioutil.ReadFile(detailsFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = json.Unmarshal(bytes, &b) | ||
if err != nil { | ||
return err | ||
} | ||
if isStringNilOrEmpty(b.RuntimeVersion) || isStringNilOrEmpty(b.DashboardVersion) || | ||
isStringNilOrEmpty(b.DaprImageName) || isStringNilOrEmpty(b.DaprImageFileName) || | ||
isStringNilOrEmpty(b.BinarySubDir) || isStringNilOrEmpty(b.ImageSubDir) { | ||
return fmt.Errorf("required fields are missing in %s", detailsFilePath) | ||
} | ||
return nil | ||
} | ||
|
||
func isStringNilOrEmpty(val *string) bool { | ||
return val == nil || strings.TrimSpace(*val) == "" | ||
} | ||
|
||
func (b *bundleDetails) getPlacementImageName() string { | ||
return *b.DaprImageName | ||
} | ||
|
||
func (b *bundleDetails) getPlacementImageFileName() string { | ||
return *b.DaprImageFileName | ||
} |
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,103 @@ | ||
/* | ||
Copyright 2021 The Dapr Authors | ||
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 standalone | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseDetails(t *testing.T) { | ||
correctDetails := `{ | ||
"daprd" : "1.7.0-rc.2", | ||
"dashboard": "0.10.0-rc.2", | ||
"cli": "1.7.0-rc.2", | ||
"daprBinarySubDir": "dist", | ||
"dockerImageSubDir": "docker", | ||
"daprImageName": "daprio/dapr:1.7.2-rc.2", | ||
"daprImageFileName": "daprio-dapr-1.7.2-rc.2.tar.gz" | ||
}` | ||
f, err := os.CreateTemp("", "*-details.json") | ||
if err != nil { | ||
t.Fatalf("error creating temp directory for testing: %s", err) | ||
} | ||
defer os.Remove(f.Name()) | ||
f.WriteString(correctDetails) | ||
f.Close() | ||
bd := bundleDetails{} | ||
err = bd.readAndParseDetails(f.Name()) | ||
assert.NoError(t, err, "expected no error on parsing correct details in file") | ||
assert.Equal(t, "1.7.0-rc.2", *bd.RuntimeVersion, "expected versions to match") | ||
assert.Equal(t, "0.10.0-rc.2", *bd.DashboardVersion, "expected versions to match") | ||
assert.Equal(t, "dist", *bd.BinarySubDir, "expected value to match") | ||
assert.Equal(t, "docker", *bd.ImageSubDir, "expected value to match") | ||
assert.Equal(t, "daprio/dapr:1.7.2-rc.2", bd.getPlacementImageName(), "expected value to match") | ||
assert.Equal(t, "daprio-dapr-1.7.2-rc.2.tar.gz", bd.getPlacementImageFileName(), "expected value to match") | ||
} | ||
|
||
func TestParseDetailsMissingDetails(t *testing.T) { | ||
missingDetails := `{ | ||
"daprd" : "1.7.0-rc.2", | ||
"dashboard": "0.10.0-rc.2", | ||
"cli": "1.7.0-rc.2", | ||
"daprImageName": "daprio/dapr:1.7.2-rc.2" | ||
"daprImageFileName": "daprio-dapr-1.7.2-rc.2.tar.gz" | ||
}` | ||
f, err := os.CreateTemp("", "*-details.json") | ||
if err != nil { | ||
t.Fatalf("error creating temp directory for testing: %s", err) | ||
} | ||
defer os.Remove(f.Name()) | ||
f.WriteString(missingDetails) | ||
f.Close() | ||
bd := bundleDetails{} | ||
err = bd.readAndParseDetails(f.Name()) | ||
assert.Error(t, err, "expected error on parsing missing details in file") | ||
} | ||
|
||
func TestParseDetailsEmptyDetails(t *testing.T) { | ||
missingDetails := `{ | ||
"daprd" : "", | ||
"dashboard": "", | ||
"cli": "1.7.0-rc.2", | ||
"daprBinarySubDir": "dist", | ||
"dockerImageSubDir": "docker", | ||
"daprImageName": "daprio/dapr:1.7.2-rc.2", | ||
"daprImageFileName": "daprio-dapr-1.7.2-rc.2.tar.gz" | ||
}` | ||
f, err := os.CreateTemp("", "*-details.json") | ||
if err != nil { | ||
t.Fatalf("error creating temp directory for testing: %s", err) | ||
} | ||
defer os.Remove(f.Name()) | ||
f.WriteString(missingDetails) | ||
f.Close() | ||
bd := bundleDetails{} | ||
err = bd.readAndParseDetails(f.Name()) | ||
assert.Error(t, err, "expected error on parsing missing details in file") | ||
} | ||
|
||
func TestParseDetailsMissingFile(t *testing.T) { | ||
f, err := os.CreateTemp("", "*-details.json") | ||
if err != nil { | ||
t.Fatalf("error creating temp directory for testing: %s", err) | ||
} | ||
f.Close() | ||
os.Remove(f.Name()) | ||
bd := bundleDetails{} | ||
err = bd.readAndParseDetails(f.Name()) | ||
assert.Error(t, err, "expected error on parsing missing details file") | ||
} |
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
Oops, something went wrong.