~nskaggs/+junk/juju-packaging-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/utils/isubuntu_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-27 20:23:11 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161027202311-sux4jk2o73p1d6rg
Re-add src

Show diffs side-by-side

added added

removed removed

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