Skip to content

Commit e7c13a8

Browse files
Migrate TestLibCommandsWithLibraryHavingInvalidVersion from test_lib.py to lib_test.go
1 parent a20baae commit e7c13a8

File tree

2 files changed

+39
-62
lines changed

2 files changed

+39
-62
lines changed

internal/integrationtest/lib/lib_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,3 +1062,42 @@ func TestLibExamplesWithCaseMismatch(t *testing.T) {
10621062
require.NotContains(t, examples, examplesPath.Join("NonBlocking", "OnDemandNonBlocking").String())
10631063
require.NotContains(t, examples, examplesPath.Join("OnDemand", "OnDemandWebPortal").String())
10641064
}
1065+
1066+
func TestLibCommandsWithLibraryHavingInvalidVersion(t *testing.T) {
1067+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
1068+
defer env.CleanUp()
1069+
1070+
_, _, err := cli.Run("update")
1071+
require.NoError(t, err)
1072+
1073+
// Install a library
1074+
_, _, err = cli.Run("lib", "install", "[email protected]")
1075+
require.NoError(t, err)
1076+
1077+
// Verifies library is correctly returned
1078+
stdout, _, err := cli.Run("lib", "list", "--format", "json")
1079+
require.NoError(t, err)
1080+
requirejson.Len(t, stdout, 1)
1081+
requirejson.Query(t, stdout, ".[0] | .library | .version", "\"0.16.1\"")
1082+
1083+
// Changes the version of the currently installed library so that it's
1084+
// invalid
1085+
libPath := cli.SketchbookDir().Join("libraries", "WiFi101", "library.properties")
1086+
require.NoError(t, libPath.WriteFile([]byte("name=WiFi101\nversion=1.0001")))
1087+
1088+
// Verifies version is now empty
1089+
stdout, _, err = cli.Run("lib", "list", "--format", "json")
1090+
require.NoError(t, err)
1091+
requirejson.Len(t, stdout, 1)
1092+
requirejson.Query(t, stdout, ".[0] | .library | .version", "null")
1093+
1094+
// Upgrade library
1095+
_, _, err = cli.Run("lib", "upgrade", "WiFi101")
1096+
require.NoError(t, err)
1097+
1098+
// Verifies library has been updated
1099+
stdout, _, err = cli.Run("lib", "list", "--format", "json")
1100+
require.NoError(t, err)
1101+
requirejson.Len(t, stdout, 1)
1102+
requirejson.Query(t, stdout, ".[0] | .library | .version != \"\"", "true")
1103+
}

test/test_lib.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -206,68 +206,6 @@ def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, da
206206
assert ble_install_dir.exists()
207207

208208

209-
def test_lib_list_using_library_with_invalid_version(run_command, data_dir):
210-
assert run_command(["update"])
211-
212-
# Install a library
213-
assert run_command(["lib", "install", "[email protected]"])
214-
215-
# Verifies library is correctly returned
216-
res = run_command(["lib", "list", "--format", "json"])
217-
assert res.ok
218-
data = json.loads(res.stdout)
219-
assert len(data) == 1
220-
assert "0.16.1" == data[0]["library"]["version"]
221-
222-
# Changes the version of the currently installed library so that it's
223-
# invalid
224-
lib_path = Path(data_dir, "libraries", "WiFi101")
225-
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
226-
227-
# Verifies version is now empty
228-
res = run_command(["lib", "list", "--format", "json"])
229-
assert res.ok
230-
data = json.loads(res.stdout)
231-
assert len(data) == 1
232-
assert "version" not in data[0]["library"]
233-
234-
235-
def test_lib_upgrade_using_library_with_invalid_version(run_command, data_dir):
236-
assert run_command(["update"])
237-
238-
# Install a library
239-
assert run_command(["lib", "install", "[email protected]"])
240-
241-
# Verifies library is correctly returned
242-
res = run_command(["lib", "list", "--format", "json"])
243-
assert res.ok
244-
data = json.loads(res.stdout)
245-
assert len(data) == 1
246-
assert "0.16.1" == data[0]["library"]["version"]
247-
248-
# Changes the version of the currently installed library so that it's
249-
# invalid
250-
lib_path = Path(data_dir, "libraries", "WiFi101")
251-
Path(lib_path, "library.properties").write_text("name=WiFi101\nversion=1.0001")
252-
253-
# Verifies version is now empty
254-
res = run_command(["lib", "list", "--format", "json"])
255-
assert res.ok
256-
data = json.loads(res.stdout)
257-
assert len(data) == 1
258-
assert "version" not in data[0]["library"]
259-
260-
# Upgrade library
261-
assert run_command(["lib", "upgrade", "WiFi101"])
262-
263-
# Verifies library has been updated
264-
res = run_command(["lib", "list", "--format", "json"])
265-
assert res.ok
266-
data = json.loads(res.stdout)
267-
assert len(data) == 1
268-
assert "" != data[0]["library"]["version"]
269-
270-
271209
def test_install_zip_lib_with_macos_metadata(run_command, data_dir, downloads_dir):
272210
# Initialize configs to enable --zip-path flag
273211
env = {

0 commit comments

Comments
 (0)