<commit_before>package coretest

import (
	"os"
	"os/exec"
	"path"
	"strings"
	"testing"
	"time"
)

const (
	CaPath                   = "/usr/share/coreos-ca-certificates/"
	CmdTimeout               = time.Second * 20
	DbusTimeout              = time.Second * 20
	DockerTimeout            = time.Second * 60
	HttpTimeout              = time.Second * 3
	PortTimeout              = time.Second * 3
	UpdateEnginePubKey       = "/usr/share/update_engine/update-payload-key.pub.pem"
	UpdateEnginePubKey<PASSWORD>256 = "d41<PASSWORD>a1<PASSWORD>ea<PASSWORD>"
	UpdateUrl                = "https://api.core-os.net/v1/update/"
)

func TestPortSsh(t *testing.T) {
	t.Parallel()
	err := CheckPort("tcp", "127.0.0.1:22", PortTimeout)
	if err != nil {
		t.Fatal(err)
	}
}

func TestUpdateEngine(t *testing.T) {
	t.Parallel()

	errc := make(chan error, 1)
	go func() {
		c := exec.Command("update_engine_client", "-omaha_url", UpdateUrl)
		err := c.Run()
		errc <- err
	}()

	select {
	case <-time.After(CmdTimeout):
		t.Fatalf("update_engine_client timed out after %s.", CmdTimeout)
	case err := <-errc:
		if err != nil {
			t.Error(err)
		}
	}

	err := CheckDbusInterface("org.chromium.UpdateEngineInterface", DbusTimeout)
	if err != nil {
		t.Fatal(err)
	}
}

func TestDockerEcho(t *testing.T) {
	t.Parallel()
	errc := make(chan error, 1)
	go func() {
		c := exec.Command("docker", "run", "busybox", "echo")
		err := c.Run()
		errc <- err
	}()
	select {
	case <-time.After(DockerTimeout):
		t.Fatalf("DockerEcho timed out after %s.", DockerTimeout)
	case err := <-errc:
		if err != nil {
			t.Error(err)
		}
	}
}

func TestTlsDate(t *testing.T) {
	t.Parallel()
	errc := make(chan error, 1)
	go func() {
		c := exec.Command("tlsdate")
		err := c.Run()
		errc <- err<commit_msg>fix(core_test): Don't set system clock, requires root<commit_after>package coretest

import (
	"os"
	"os/exec"
	"path"
	"strings"
	"testing"
	"time"
)

const (
	CaPath                   = "/usr/share/coreos-ca-certificates/"
	CmdTimeout               = time.Second * 20
	DbusTimeout              = time.Second * 20
	DockerTimeout            = time.Second * 60
	HttpTimeout              = time.Second * 3
	PortTimeout              = time.Second * 3
	UpdateEnginePubKey       = "/usr/share/update_engine/update-payload-key.pub.pem"
	UpdateEnginePubKeySha256 = "d410d94dc56a1cba8df71c94ea6925811e44b09416f66958ab7a453f0731d80e"
	UpdateUrl                = "https://api.core-os.net/v1/update/"
)

func TestPortSsh(t *testing.T) {
	t.Parallel()
	err := CheckPort("tcp", "127.0.0.1:22", PortTimeout)
	if err != nil {
		t.Fatal(err)
	}
}

func TestUpdateEngine(t *testing.T) {
	t.Parallel()

	errc := make(chan error, 1)
	go func() {
		c := exec.Command("update_engine_client", "-omaha_url", UpdateUrl)
		err := c.Run()
		errc <- err
	}()

	select {
	case <-time.After(CmdTimeout):
		t.Fatalf("update_engine_client timed out after %s.", CmdTimeout)
	case err := <-errc:
		if err != nil {
			t.Error(err)
		}
	}

	err := CheckDbusInterface("org.chromium.UpdateEngineInterface", DbusTimeout)
	if err != nil {
		t.Fatal(err)
	}
}

func TestDockerEcho(t *testing.T) {
	t.Parallel()
	errc := make(chan error, 1)
	go func() {
		c := exec.Command("docker", "run", "busybox", "echo")
		err := c.Run()
		errc <- err
	}()
	select {
	case <-time.After(DockerTimeout):
		t.Fatalf("DockerEcho timed out after %s.", DockerTimeout)
	case err := <-errc:
		if err != nil {
			t.Error(err)
		}
	}
}

func TestTlsDate(t *testing.T) {
	t.Parallel()
	errc := make(chan error, 1)
	go func() {
		c := exec.Command("tlsdate", "--dont-set-clock")
		err := c.Run()
		errc <- err
{'fraction_non_alphanumeric': 0.1628808864265928, 'fraction_numerical': 0.025207756232686982, 'mean_word_length': 2.908008658008658, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6289170', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1397, 'n_words': 280}