diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/go.py')
| -rw-r--r-- | meta/lib/oeqa/runtime/cases/go.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/cases/go.py b/meta/lib/oeqa/runtime/cases/go.py index 39a80f4dca..fc7959b5f4 100644 --- a/meta/lib/oeqa/runtime/cases/go.py +++ b/meta/lib/oeqa/runtime/cases/go.py | |||
| @@ -4,10 +4,78 @@ | |||
| 4 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | import os | ||
| 7 | from oeqa.runtime.case import OERuntimeTestCase | 8 | from oeqa.runtime.case import OERuntimeTestCase |
| 8 | from oeqa.core.decorator.depends import OETestDepends | 9 | from oeqa.core.decorator.depends import OETestDepends |
| 9 | from oeqa.runtime.decorator.package import OEHasPackage | 10 | from oeqa.runtime.decorator.package import OEHasPackage |
| 10 | 11 | ||
| 12 | class GoCompileTest(OERuntimeTestCase): | ||
| 13 | |||
| 14 | @classmethod | ||
| 15 | def setUp(cls): | ||
| 16 | dst = '/tmp/' | ||
| 17 | src = os.path.join(cls.tc.files_dir, 'test.go') | ||
| 18 | cls.tc.target.copyTo(src, dst) | ||
| 19 | |||
| 20 | @classmethod | ||
| 21 | def tearDown(cls): | ||
| 22 | files = '/tmp/test.go /tmp/test' | ||
| 23 | cls.tc.target.run('rm %s' % files) | ||
| 24 | dirs = '/tmp/hello-go' | ||
| 25 | cls.tc.target.run('rm -r %s' % dirs) | ||
| 26 | |||
| 27 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 28 | @OEHasPackage('go') | ||
| 29 | @OEHasPackage('go-runtime') | ||
| 30 | @OEHasPackage('go-runtime-dev') | ||
| 31 | @OEHasPackage('openssh-scp') | ||
| 32 | def test_go_compile(self): | ||
| 33 | # Check if go is available | ||
| 34 | status, output = self.target.run('which go') | ||
| 35 | if status != 0: | ||
| 36 | self.skipTest('go command not found, output: %s' % output) | ||
| 37 | |||
| 38 | # Compile the simple Go program | ||
| 39 | status, output = self.target.run('go build -o /tmp/test /tmp/test.go') | ||
| 40 | msg = 'go compile failed, output: %s' % output | ||
| 41 | self.assertEqual(status, 0, msg=msg) | ||
| 42 | |||
| 43 | # Run the compiled program | ||
| 44 | status, output = self.target.run('/tmp/test') | ||
| 45 | msg = 'running compiled file failed, output: %s' % output | ||
| 46 | self.assertEqual(status, 0, msg=msg) | ||
| 47 | |||
| 48 | @OETestDepends(['ssh.SSHTest.test_ssh']) | ||
| 49 | @OEHasPackage('go') | ||
| 50 | @OEHasPackage('go-runtime') | ||
| 51 | @OEHasPackage('go-runtime-dev') | ||
| 52 | @OEHasPackage('openssh-scp') | ||
| 53 | def test_go_module(self): | ||
| 54 | # Check if go is available | ||
| 55 | status, output = self.target.run('which go') | ||
| 56 | if status != 0: | ||
| 57 | self.skipTest('go command not found, output: %s' % output) | ||
| 58 | |||
| 59 | # Create a simple Go module | ||
| 60 | status, output = self.target.run('mkdir -p /tmp/hello-go') | ||
| 61 | msg = 'mkdir failed, output: %s' % output | ||
| 62 | self.assertEqual(status, 0, msg=msg) | ||
| 63 | |||
| 64 | # Copy the existing test.go file to the module | ||
| 65 | status, output = self.target.run('cp /tmp/test.go /tmp/hello-go/main.go') | ||
| 66 | msg = 'copying test.go failed, output: %s' % output | ||
| 67 | self.assertEqual(status, 0, msg=msg) | ||
| 68 | |||
| 69 | # Build the module | ||
| 70 | status, output = self.target.run('cd /tmp/hello-go && go build -o hello main.go') | ||
| 71 | msg = 'go build failed, output: %s' % output | ||
| 72 | self.assertEqual(status, 0, msg=msg) | ||
| 73 | |||
| 74 | # Run the module | ||
| 75 | status, output = self.target.run('cd /tmp/hello-go && ./hello') | ||
| 76 | msg = 'running go module failed, output: %s' % output | ||
| 77 | self.assertEqual(status, 0, msg=msg) | ||
| 78 | |||
| 11 | class GoHelloworldTest(OERuntimeTestCase): | 79 | class GoHelloworldTest(OERuntimeTestCase): |
| 12 | @OETestDepends(['ssh.SSHTest.test_ssh']) | 80 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 13 | @OEHasPackage(['go-helloworld']) | 81 | @OEHasPackage(['go-helloworld']) |
