-
Notifications
You must be signed in to change notification settings - Fork 89
/
isubuntu_test.go
51 lines (41 loc) · 1.14 KB
/
isubuntu_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package utils_test
import (
"fmt"
"runtime"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/utils/v4"
)
type IsUbuntuSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&IsUbuntuSuite{})
func (s *IsUbuntuSuite) patchLsbRelease(c *gc.C, name string) {
var content string
var execName string
if runtime.GOOS != "windows" {
content = fmt.Sprintf("#!/bin/bash --norc\n%s", name)
execName = "lsb_release"
} else {
execName = "lsb_release.bat"
content = fmt.Sprintf("@echo off\r\n%s", name)
}
patchExecutable(s, c.MkDir(), execName, content)
}
func (s *IsUbuntuSuite) TestIsUbuntu(c *gc.C) {
s.patchLsbRelease(c, "echo Ubuntu")
c.Assert(utils.IsUbuntu(), jc.IsTrue)
}
func (s *IsUbuntuSuite) TestIsNotUbuntu(c *gc.C) {
s.patchLsbRelease(c, "echo Windows NT")
c.Assert(utils.IsUbuntu(), jc.IsFalse)
}
func (s *IsUbuntuSuite) TestIsNotUbuntuLsbReleaseNotFound(c *gc.C) {
if runtime.GOOS != "windows" {
s.patchLsbRelease(c, "exit 127")
}
c.Assert(utils.IsUbuntu(), jc.IsFalse)
}