-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(test): add unit test * feat(test): add unit test * feat(test): add unit test * chore(test): fix code review * chore(test): fix code review * chore(test): fix code review * chore(test): fix code review * feat(test): add unit test * chore(test): add header
- Loading branch information
Showing
5 changed files
with
475 additions
and
0 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,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 env | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
import ( | ||
"github.com/arana-db/arana/pkg/constants" | ||
) | ||
|
||
func TestIsDevelopEnvironment(t *testing.T) { | ||
// Test case 1: Environment variable is set to "1" | ||
os.Setenv(constants.EnvDevelopEnvironment, "1") | ||
isDev := IsDevelopEnvironment() | ||
assert.True(t, isDev) | ||
os.Unsetenv(constants.EnvDevelopEnvironment) | ||
|
||
// Test case 2: Environment variable is set to "yes" | ||
os.Setenv(constants.EnvDevelopEnvironment, "yes") | ||
isDev = IsDevelopEnvironment() | ||
assert.True(t, isDev) | ||
os.Unsetenv(constants.EnvDevelopEnvironment) | ||
|
||
// Test case 3: Environment variable is set to "on" | ||
os.Setenv(constants.EnvDevelopEnvironment, "on") | ||
isDev = IsDevelopEnvironment() | ||
assert.True(t, isDev) | ||
os.Unsetenv(constants.EnvDevelopEnvironment) | ||
|
||
// Test case 4: Environment variable is set to "true" | ||
os.Setenv(constants.EnvDevelopEnvironment, "true") | ||
isDev = IsDevelopEnvironment() | ||
assert.True(t, isDev) | ||
os.Unsetenv(constants.EnvDevelopEnvironment) | ||
|
||
// Test case 5: Environment variable is set to any other value | ||
//os.Setenv(constants.EnvDevelopEnvironment, "false") | ||
//isDev = IsDevelopEnvironment() | ||
//if isDev { | ||
// t.Errorf("Expected IsDevelopEnvironment() to return false, but got true") | ||
//} | ||
} |
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,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 file | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsYaml(t *testing.T) { | ||
// Test with a valid YAML file | ||
path := "example.yaml" | ||
result := IsYaml(path) | ||
assert.True(t, result) | ||
|
||
// Test with a valid YML file | ||
path = "example.yml" | ||
result = IsYaml(path) | ||
assert.True(t, result) | ||
|
||
// Test with an invalid file extension | ||
path = "example.txt" | ||
result = IsYaml(path) | ||
assert.False(t, result) | ||
} |
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,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 identity | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetNodeIdentity(t *testing.T) { | ||
// Test case 1: Testing when AranaNodeId is set | ||
expectedNodeId := "some-node-id" | ||
os.Setenv("ARANA_NODE_ID", expectedNodeId) | ||
assert.Equal(t, expectedNodeId, GetNodeIdentity()) | ||
os.Unsetenv("ARANA_NODE_ID") | ||
|
||
// Test case 2: Testing when PodName is set | ||
expectedPodName := "some-pod-name" | ||
os.Setenv("POD_NAME", expectedPodName) | ||
assert.Equal(t, expectedPodName, GetNodeIdentity()) | ||
os.Unsetenv("POD_NAME") | ||
|
||
// Test case 3: Testing when neither AranaNodeId nor PodName is set | ||
//expectedIP := "some-ip" | ||
//net.FindSelfIP = func() (string, error) { | ||
// return expectedIP, nil | ||
//} | ||
//assert.Equal(t, expectedIP, GetNodeIdentity()) | ||
//net.FindSelfIP = nil | ||
|
||
// Test case 4: Testing when all values are empty | ||
//expectedUUID := "some-uuid" | ||
//uuid.NewString = func() string { | ||
// return expectedUUID | ||
//} | ||
//assert.Equal(t, expectedUUID, GetNodeIdentity()) | ||
//uuid.NewString = nil | ||
} |
Oops, something went wrong.