2464
test_toggle_conf_name (void)
2466
char override_ext[] = ".override";
2467
char dirname[PATH_MAX];
2468
char filename[PATH_MAX];
2473
TEST_FUNCTION_FEATURE ("toggle_conf_name",
2474
"changing conf to override");
2476
TEST_FILENAME (dirname);
2477
strcpy (filename, dirname);
2478
strcat (filename, "/foo.conf");
2479
f = toggle_conf_name (NULL, filename);
2480
TEST_NE_P (f, NULL);
2482
p = strstr (f, ".override");
2483
TEST_NE_P (p, NULL);
2484
TEST_EQ_P (p, f+strlen (f) - strlen (override_ext));
2487
TEST_FEATURE ("changing override to conf");
2488
strcpy (filename, dirname);
2489
strcat (filename, "/bar.override");
2490
f = toggle_conf_name (NULL, filename);
2491
TEST_NE_P (f, NULL);
2493
p = strstr (f, ".conf");
2494
TEST_NE_P (p, NULL);
2495
TEST_EQ_P (p, f+strlen (f) - strlen (".conf"));
2498
/* test parent param */
2499
job = job_class_new (NULL, "foo", NULL);
2500
TEST_NE_P (job, NULL);
2502
f = toggle_conf_name (job, filename);
2503
TEST_NE_P (f, NULL);
2505
TEST_EQ (TRUE, nih_alloc_parent (f, job));
2511
test_override (void)
2516
int ret, fd[4096], i = 0;
2517
char dirname[PATH_MAX];
2518
char filename[PATH_MAX], override[PATH_MAX];
2522
program_name = "test";
2523
nih_log_set_priority (NIH_LOG_FATAL);
2525
TEST_ENSURE_CLEAN_ENV ();
2526
TEST_GROUP ("override files");
2528
/* Make sure that we have inotify before performing some tests... */
2529
if ((fd[0] = inotify_init ()) < 0) {
2530
printf ("SKIP: inotify not available\n");
2536
/* Explicit test of behaviour prior to introduction of override files.
2538
* conf with no override before watch:
2541
* ensure conf loaded
2543
* ensure conf updated
2545
* ensure conf deleted
2547
TEST_FEATURE ("with pre-override environment (conf with no override before watch)");
2548
TEST_ENSURE_CLEAN_ENV ();
2549
TEST_FILENAME (dirname);
2550
TEST_EQ (mkdir (dirname, 0755), 0);
2553
strcpy (filename, dirname);
2554
strcat (filename, "/foo.conf");
2555
f = fopen (filename, "w");
2556
TEST_NE_P (f, NULL);
2557
fprintf (f, "start on started\n");
2558
fprintf (f, "emits hello\n");
2562
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2563
TEST_NE_P (source, NULL);
2564
ret = conf_source_reload (source);
2567
/* ensure conf loaded */
2568
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2569
TEST_NE_P (file, NULL);
2570
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2571
TEST_NE_P (job, NULL);
2572
TEST_EQ_P (file->job, job);
2573
TEST_EQ_STR ((job->emits)[0], "hello");
2574
TEST_NE_P (job->start_on, NULL);
2577
f = fopen (filename, "a");
2578
TEST_NE_P (f, NULL);
2579
fprintf (f, "manual\n");
2582
TEST_FORCE_WATCH_UPDATE();
2584
/* ensure conf updated */
2585
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2586
TEST_NE_P (file, NULL);
2587
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2588
TEST_NE_P (job, NULL);
2589
TEST_EQ_P (job->start_on, NULL);
2594
TEST_FORCE_WATCH_UPDATE();
2596
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2597
TEST_EQ_P (job, NULL);
2598
TEST_HASH_EMPTY (job_classes);
2599
TEST_HASH_EMPTY (source->files);
2601
TEST_FORCE_WATCH_UPDATE();
2603
/* ensure conf deleted */
2604
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2605
TEST_EQ_P (file, NULL);
2608
TEST_EQ (rmdir (dirname), 0);
2611
/* Explicit test of behaviour prior to introduction of override files.
2613
* conf with no override after watch:
2616
* ensure conf loaded
2618
* ensure conf updated
2620
* ensure conf deleted
2622
TEST_ENSURE_CLEAN_ENV ();
2623
TEST_FEATURE ("with pre-override environment (conf with no override after watch)");
2624
TEST_FILENAME (dirname);
2625
TEST_EQ (mkdir (dirname, 0755), 0);
2628
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2629
TEST_NE_P (source, NULL);
2630
ret = conf_source_reload (source);
2634
strcpy (filename, dirname);
2635
strcat (filename, "/foo.conf");
2636
f = fopen (filename, "w");
2637
TEST_NE_P (f, NULL);
2638
fprintf (f, "start on started\n");
2639
fprintf (f, "emits hello\n");
2642
TEST_FORCE_WATCH_UPDATE();
2644
/* ensure conf loaded */
2645
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2646
TEST_NE_P (file, NULL);
2647
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2648
TEST_NE_P (job, NULL);
2649
TEST_EQ_P (file->job, job);
2650
TEST_EQ_STR ((job->emits)[0], "hello");
2653
f = fopen (filename, "a");
2654
TEST_NE_P (f, NULL);
2655
fprintf (f, "manual\n");
2658
TEST_FORCE_WATCH_UPDATE();
2660
/* ensure conf updated */
2661
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2662
TEST_NE_P (job, NULL);
2663
TEST_EQ_P (job->start_on, NULL);
2668
TEST_FORCE_WATCH_UPDATE();
2670
/* ensure conf deleted */
2671
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2672
TEST_EQ_P (file, NULL);
2674
TEST_EQ (rmdir (dirname), 0);
2677
TEST_FEATURE ("ensure lone override ignored before watch");
2678
TEST_ENSURE_CLEAN_ENV ();
2679
TEST_FILENAME (dirname);
2680
TEST_EQ (mkdir (dirname, 0755), 0);
2682
/* create override */
2683
strcpy (filename, dirname);
2684
strcat (filename, "/foo.override");
2685
f = fopen (filename, "w");
2686
TEST_NE_P (f, NULL);
2687
fprintf (f, "manual\n");
2691
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2692
TEST_NE_P (source, NULL);
2693
ret = conf_source_reload (source);
2696
TEST_FORCE_WATCH_UPDATE();
2698
/* ensure no conf object created */
2699
TEST_HASH_EMPTY (source->files);
2700
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2701
TEST_EQ_P (file, NULL);
2702
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2703
TEST_EQ_P (job, NULL);
2705
/* update override */
2706
f = fopen (filename, "a");
2707
TEST_NE_P (f, NULL);
2708
fprintf (f, "author \"me\"\n");
2711
TEST_FORCE_WATCH_UPDATE();
2713
/* ensure no conf object created */
2714
TEST_HASH_EMPTY (source->files);
2715
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2716
TEST_EQ_P (file, NULL);
2717
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2718
TEST_EQ_P (job, NULL);
2720
/* delete override */
2723
TEST_EQ (rmdir (dirname), 0);
2726
TEST_FEATURE ("ensure lone override ignored after watch");
2727
TEST_ENSURE_CLEAN_ENV ();
2728
TEST_FILENAME (dirname);
2729
TEST_EQ (mkdir (dirname, 0755), 0);
2732
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2733
TEST_NE_P (source, NULL);
2734
ret = conf_source_reload (source);
2737
strcpy (filename, dirname);
2738
strcat (filename, "/bar.override");
2739
f = fopen (filename, "w");
2740
TEST_NE_P (f, NULL);
2741
fprintf (f, "manual\n");
2744
TEST_FORCE_WATCH_UPDATE();
2746
/* ensure no conf object created */
2747
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2748
TEST_EQ_P (file, NULL);
2749
job = (JobClass *)nih_hash_lookup (job_classes, "bar");
2750
TEST_EQ_P (job, NULL);
2752
/* delete override */
2755
TEST_FORCE_WATCH_UPDATE();
2757
/* ensure override still not present */
2758
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2759
TEST_EQ_P (file, NULL);
2760
job = (JobClass *)nih_hash_lookup (job_classes, "bar");
2761
TEST_EQ_P (job, NULL);
2764
TEST_EQ (rmdir (dirname), 0);
2767
TEST_FEATURE ("create conf, watch, then create/modify/delete override");
2768
TEST_ENSURE_CLEAN_ENV ();
2769
TEST_FILENAME (dirname);
2770
TEST_EQ (mkdir (dirname, 0755), 0);
2773
strcpy (filename, dirname);
2774
strcat (filename, "/foo.conf");
2775
f = fopen (filename, "w");
2776
TEST_NE_P (f, NULL);
2777
fprintf (f, "start on started\n");
2778
fprintf (f, "emits hello\n");
2782
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2783
TEST_NE_P (source, NULL);
2784
ret = conf_source_reload (source);
2787
/* ensure conf loaded */
2788
TEST_HASH_NOT_EMPTY (source->files);
2789
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2790
TEST_NE_P (file, NULL);
2791
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2792
TEST_NE_P (job, NULL);
2793
TEST_EQ_P (file->job, job);
2794
TEST_EQ_STR ((job->emits)[0], "hello");
2795
TEST_EQ_P ((job->emits)[1], NULL);
2796
TEST_NE_P (job->start_on, NULL);
2798
/* create override */
2799
strcpy (override, dirname);
2800
strcat (override, "/foo.override");
2801
f = fopen (override, "w");
2802
TEST_NE_P (f, NULL);
2803
fprintf (f, "manual\n");
2806
TEST_HASH_NOT_EMPTY (source->files);
2807
TEST_FORCE_WATCH_UPDATE();
2809
/* ensure conf updated */
2810
TEST_HASH_NOT_EMPTY (source->files);
2811
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2812
TEST_NE_P (file, NULL);
2813
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2814
TEST_NE_P (job, NULL);
2815
TEST_EQ_P (job->start_on, NULL);
2817
/* ensure no override in hash */
2818
file = (ConfFile *)nih_hash_lookup (source->files, override);
2819
TEST_EQ_P (file, NULL);
2821
/* modify override */
2822
f = fopen (override, "a");
2823
TEST_NE_P (f, NULL);
2824
fprintf (f, "emits world\n");
2827
TEST_FORCE_WATCH_UPDATE();
2829
/* ensure conf updated */
2830
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2831
TEST_NE_P (file, NULL);
2832
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2833
TEST_NE_P (job, NULL);
2834
TEST_EQ_P (job->start_on, NULL);
2835
TEST_EQ_STR ((job->emits)[0], "hello");
2836
TEST_EQ_STR ((job->emits)[1], "world");
2838
/* delete override */
2841
TEST_FORCE_WATCH_UPDATE();
2843
/* ensure conf reverted */
2844
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2845
TEST_NE_P (file, NULL);
2846
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2847
TEST_NE_P (job, NULL);
2848
TEST_NE_P (job->start_on, NULL);
2849
TEST_EQ_STR ((job->emits)[0], "hello");
2850
TEST_EQ_P ((job->emits)[1], NULL);
2854
TEST_EQ (rmdir (dirname), 0);
2857
TEST_FEATURE ("create watch, conf, then create/modify/delete override");
2858
TEST_ENSURE_CLEAN_ENV ();
2859
TEST_FILENAME (dirname);
2860
TEST_EQ (mkdir (dirname, 0755), 0);
2863
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2864
TEST_NE_P (source, NULL);
2865
ret = conf_source_reload (source);
2869
strcpy (filename, dirname);
2870
strcat (filename, "/foo.conf");
2871
f = fopen (filename, "w");
2872
TEST_NE_P (f, NULL);
2873
fprintf (f, "start on started\n");
2874
fprintf (f, "emits hello\n");
2877
TEST_FORCE_WATCH_UPDATE();
2879
/* ensure conf loaded */
2880
TEST_HASH_NOT_EMPTY (source->files);
2881
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2882
TEST_NE_P (file, NULL);
2883
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2884
TEST_NE_P (job, NULL);
2885
TEST_EQ_P (file->job, job);
2886
TEST_EQ_STR ((job->emits)[0], "hello");
2887
TEST_EQ_P ((job->emits)[1], NULL);
2888
TEST_NE_P (job->start_on, NULL);
2890
/* create override */
2891
strcpy (override, dirname);
2892
strcat (override, "/foo.override");
2893
f = fopen (override, "w");
2894
TEST_NE_P (f, NULL);
2895
fprintf (f, "manual\n");
2898
TEST_HASH_NOT_EMPTY (source->files);
2899
TEST_FORCE_WATCH_UPDATE();
2901
/* ensure conf updated */
2902
TEST_HASH_NOT_EMPTY (source->files);
2903
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2904
TEST_NE_P (file, NULL);
2905
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2906
TEST_NE_P (job, NULL);
2907
TEST_EQ_P (job->start_on, NULL);
2909
/* ensure no override in hash */
2910
file = (ConfFile *)nih_hash_lookup (source->files, override);
2911
TEST_EQ_P (file, NULL);
2913
/* modify override */
2914
f = fopen (override, "a");
2915
TEST_NE_P (f, NULL);
2916
fprintf (f, "emits world\n");
2919
TEST_FORCE_WATCH_UPDATE();
2921
/* ensure conf updated */
2922
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2923
TEST_NE_P (file, NULL);
2924
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2925
TEST_NE_P (job, NULL);
2926
TEST_EQ_P (job->start_on, NULL);
2927
TEST_EQ_STR ((job->emits)[0], "hello");
2928
TEST_EQ_STR ((job->emits)[1], "world");
2930
/* delete override */
2933
TEST_FORCE_WATCH_UPDATE();
2935
/* ensure conf reverted */
2936
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2937
TEST_NE_P (file, NULL);
2938
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2939
TEST_NE_P (job, NULL);
2940
TEST_NE_P (job->start_on, NULL);
2941
TEST_EQ_STR ((job->emits)[0], "hello");
2942
TEST_EQ_P ((job->emits)[1], NULL);
2946
TEST_EQ (rmdir (dirname), 0);
2949
TEST_FEATURE ("create override, watch, then create/modify/delete conf");
2950
TEST_ENSURE_CLEAN_ENV ();
2951
TEST_FILENAME (dirname);
2952
TEST_EQ (mkdir (dirname, 0755), 0);
2954
strcpy (filename, dirname);
2955
strcat (filename, "/foo.conf");
2956
strcpy (override, dirname);
2957
strcat (override, "/foo.override");
2959
/* create override */
2960
f = fopen (override, "w");
2961
TEST_NE_P (f, NULL);
2962
fprintf (f, "manual\n");
2963
fprintf (f, "author \"bar\"\n");
2967
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
2968
TEST_NE_P (source, NULL);
2969
ret = conf_source_reload (source);
2972
TEST_FORCE_WATCH_UPDATE();
2974
/* ensure no conf object created */
2975
TEST_HASH_EMPTY (source->files);
2976
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2977
TEST_EQ_P (file, NULL);
2978
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2979
TEST_EQ_P (job, NULL);
2982
f = fopen (filename, "w");
2983
TEST_NE_P (f, NULL);
2984
fprintf (f, "start on started\n");
2985
fprintf (f, "emits hello\n");
2986
fprintf (f, "author \"foo\"\n");
2989
TEST_FORCE_WATCH_UPDATE();
2991
/* ensure conf loaded */
2992
file = (ConfFile *)nih_hash_lookup (source->files, filename);
2993
TEST_NE_P (file, NULL);
2994
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
2995
TEST_NE_P (job, NULL);
2996
TEST_EQ_P (file->job, job);
2997
TEST_EQ_STR ((job->emits)[0], "hello");
2999
/* should pick up override, *NOT* conf */
3000
TEST_EQ_P (job->start_on, NULL);
3001
TEST_EQ_STR (job->author, "bar");
3004
f = fopen (filename, "w");
3005
TEST_NE_P (f, NULL);
3006
fprintf (f, "start on wibble\n");
3007
fprintf (f, "emits moo\n");
3010
TEST_FORCE_WATCH_UPDATE();
3012
/* ensure conf reloaded and updated with override */
3013
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3014
TEST_NE_P (file, NULL);
3015
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3016
TEST_NE_P (job, NULL);
3017
TEST_EQ_P (file->job, job);
3018
TEST_EQ_STR ((job->emits)[0], "moo");
3020
/* should pick up override, *NOT* conf */
3021
TEST_EQ_P (job->start_on, NULL);
3022
TEST_EQ_STR (job->author, "bar");
3027
TEST_FORCE_WATCH_UPDATE();
3029
/* ensure conf object deleted */
3030
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3031
TEST_EQ_P (file, NULL);
3032
TEST_HASH_EMPTY (source->files);
3033
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3034
TEST_EQ_P (job, NULL);
3035
file = (ConfFile *)nih_hash_lookup (source->files, override);
3036
TEST_EQ_P (file, NULL);
3040
/* ensure no conf object still */
3041
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3042
TEST_EQ_P (file, NULL);
3043
TEST_HASH_EMPTY (source->files);
3044
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3045
TEST_EQ_P (job, NULL);
3046
file = (ConfFile *)nih_hash_lookup (source->files, override);
3047
TEST_EQ_P (file, NULL);
3050
TEST_EQ (rmdir (dirname), 0);
3053
TEST_FEATURE ("create watch, override, then create/modify/delete conf");
3054
TEST_ENSURE_CLEAN_ENV ();
3055
TEST_FILENAME (dirname);
3056
TEST_EQ (mkdir (dirname, 0755), 0);
3059
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3060
TEST_NE_P (source, NULL);
3061
ret = conf_source_reload (source);
3064
strcpy (filename, dirname);
3065
strcat (filename, "/foo.conf");
3066
strcpy (override, dirname);
3067
strcat (override, "/foo.override");
3069
/* create override */
3070
f = fopen (override, "w");
3071
TEST_NE_P (f, NULL);
3072
fprintf (f, "manual\n");
3073
fprintf (f, "author \"bar\"\n");
3076
TEST_FORCE_WATCH_UPDATE();
3078
/* ensure no conf object created */
3079
TEST_HASH_EMPTY (source->files);
3080
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3081
TEST_EQ_P (file, NULL);
3082
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3083
TEST_EQ_P (job, NULL);
3086
f = fopen (filename, "w");
3087
TEST_NE_P (f, NULL);
3088
fprintf (f, "start on started\n");
3089
fprintf (f, "emits hello\n");
3090
fprintf (f, "author \"foo\"\n");
3093
TEST_FORCE_WATCH_UPDATE();
3095
/* ensure conf loaded */
3096
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3097
TEST_NE_P (file, NULL);
3098
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3099
TEST_NE_P (job, NULL);
3100
TEST_EQ_P (file->job, job);
3101
TEST_EQ_STR ((job->emits)[0], "hello");
3103
/* should pick up override, *NOT* conf */
3104
TEST_EQ_P (job->start_on, NULL);
3105
TEST_EQ_STR (job->author, "bar");
3108
f = fopen (filename, "w");
3109
TEST_NE_P (f, NULL);
3110
fprintf (f, "start on wibble\n");
3111
fprintf (f, "emits moo\n");
3114
TEST_FORCE_WATCH_UPDATE();
3116
/* ensure conf reloaded and updated with override */
3117
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3118
TEST_NE_P (file, NULL);
3119
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3120
TEST_NE_P (job, NULL);
3121
TEST_EQ_P (file->job, job);
3122
TEST_EQ_STR ((job->emits)[0], "moo");
3124
/* should pick up override, *NOT* conf */
3125
TEST_EQ_P (job->start_on, NULL);
3126
TEST_EQ_STR (job->author, "bar");
3131
TEST_FORCE_WATCH_UPDATE();
3133
/* ensure conf object deleted */
3134
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3135
TEST_EQ_P (file, NULL);
3136
TEST_HASH_EMPTY (source->files);
3137
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3138
TEST_EQ_P (job, NULL);
3139
file = (ConfFile *)nih_hash_lookup (source->files, override);
3140
TEST_EQ_P (file, NULL);
3144
/* ensure no conf object still */
3145
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3146
TEST_EQ_P (file, NULL);
3147
TEST_HASH_EMPTY (source->files);
3148
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3149
TEST_EQ_P (job, NULL);
3150
file = (ConfFile *)nih_hash_lookup (source->files, override);
3151
TEST_EQ_P (file, NULL);
3154
TEST_EQ (rmdir (dirname), 0);
3157
TEST_FEATURE ("create override, watch, conf, then modify/delete override");
3158
TEST_ENSURE_CLEAN_ENV ();
3159
TEST_FILENAME (dirname);
3160
TEST_EQ (mkdir (dirname, 0755), 0);
3162
strcpy (filename, dirname);
3163
strcat (filename, "/foo.conf");
3164
strcpy (override, dirname);
3165
strcat (override, "/foo.override");
3167
/* create override */
3168
f = fopen (override, "w");
3169
TEST_NE_P (f, NULL);
3170
fprintf (f, "manual\n");
3171
fprintf (f, "author \"bar\"\n");
3175
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3176
TEST_NE_P (source, NULL);
3177
ret = conf_source_reload (source);
3180
TEST_FORCE_WATCH_UPDATE();
3182
/* ensure no conf object created */
3183
TEST_HASH_EMPTY (source->files);
3184
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3185
TEST_EQ_P (file, NULL);
3186
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3187
TEST_EQ_P (job, NULL);
3190
f = fopen (filename, "w");
3191
TEST_NE_P (f, NULL);
3192
fprintf (f, "start on started\n");
3193
fprintf (f, "emits hello\n");
3194
fprintf (f, "author \"foo\"\n");
3197
/* FIXME: crashes here */
3198
TEST_FORCE_WATCH_UPDATE();
3200
/* ensure conf loaded */
3201
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3202
TEST_NE_P (file, NULL);
3203
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3204
TEST_NE_P (job, NULL);
3205
TEST_EQ_P (file->job, job);
3206
TEST_EQ_STR ((job->emits)[0], "hello");
3208
/* should pick up override, *NOT* conf */
3209
TEST_EQ_P (job->start_on, NULL);
3210
TEST_EQ_STR (job->author, "bar");
3212
/* modify override */
3213
f = fopen (override, "w");
3214
TEST_NE_P (f, NULL);
3215
fprintf (f, "author \"meh\"\n");
3216
fprintf (f, "env wibble=wobble\n");
3217
fprintf (f, "manual\n");
3220
TEST_FORCE_WATCH_UPDATE();
3222
/* ensure conf reloaded and updated with override */
3223
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3224
TEST_NE_P (file, NULL);
3225
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3226
TEST_NE_P (job, NULL);
3227
TEST_EQ_P (file->job, job);
3228
TEST_EQ_STR ((job->emits)[0], "hello");
3230
/* should pick up override, *NOT* conf */
3231
TEST_EQ_P (job->start_on, NULL);
3232
TEST_EQ_STR (job->author, "meh");
3233
TEST_EQ_STR ((job->env)[0], "wibble=wobble");
3235
/* delete override */
3238
TEST_FORCE_WATCH_UPDATE();
3240
/* ensure conf object reverted */
3241
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3242
TEST_NE_P (file, NULL);
3243
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3244
TEST_NE_P (job, NULL);
3245
TEST_NE_P (job->start_on, NULL);
3246
TEST_EQ_STR (job->author, "foo");
3247
TEST_EQ_P (job->env, NULL);
3248
TEST_EQ_STR ((job->emits)[0], "hello");
3252
TEST_EQ (rmdir (dirname), 0);
3255
TEST_FEATURE ("create watch, override, conf, then modify/delete override");
3256
TEST_ENSURE_CLEAN_ENV ();
3257
TEST_FILENAME (dirname);
3258
TEST_EQ (mkdir (dirname, 0755), 0);
3260
strcpy (filename, dirname);
3261
strcat (filename, "/foo.conf");
3262
strcpy (override, dirname);
3263
strcat (override, "/foo.override");
3266
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3267
TEST_NE_P (source, NULL);
3268
ret = conf_source_reload (source);
3271
TEST_FORCE_WATCH_UPDATE();
3273
/* create override */
3274
f = fopen (override, "w");
3275
TEST_NE_P (f, NULL);
3276
fprintf (f, "manual\n");
3277
fprintf (f, "author \"bar\"\n");
3280
TEST_FORCE_WATCH_UPDATE();
3283
f = fopen (filename, "w");
3284
TEST_NE_P (f, NULL);
3285
fprintf (f, "start on started\n");
3286
fprintf (f, "emits hello\n");
3287
fprintf (f, "author \"foo\"\n");
3290
TEST_FORCE_WATCH_UPDATE();
3292
/* ensure conf loaded */
3293
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3294
TEST_NE_P (file, NULL);
3295
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3296
TEST_NE_P (job, NULL);
3297
TEST_EQ_P (file->job, job);
3298
TEST_EQ_STR ((job->emits)[0], "hello");
3300
/* should pick up override, *NOT* conf */
3301
TEST_EQ_P (job->start_on, NULL);
3302
TEST_EQ_STR (job->author, "bar");
3304
/* update override */
3305
f = fopen (override, "a");
3306
TEST_NE_P (f, NULL);
3307
fprintf (f, "author \"me\"\n");
3308
fprintf (f, "env wibble=wobble\n");
3311
TEST_FORCE_WATCH_UPDATE();
3313
/* ensure conf reloaded and updated with override */
3314
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3315
TEST_NE_P (file, NULL);
3316
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3317
TEST_NE_P (job, NULL);
3318
TEST_EQ_P (file->job, job);
3319
TEST_EQ_STR ((job->emits)[0], "hello");
3321
/* should pick up override, *NOT* conf */
3322
TEST_EQ_P (job->start_on, NULL);
3323
TEST_EQ_STR (job->author, "me");
3324
TEST_EQ_STR ((job->env)[0], "wibble=wobble");
3326
TEST_FORCE_WATCH_UPDATE();
3328
/* delete override */
3331
TEST_FORCE_WATCH_UPDATE();
3333
/* ensure conf loaded */
3334
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3335
TEST_NE_P (file, NULL);
3336
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3337
TEST_NE_P (job, NULL);
3338
TEST_EQ_P (file->job, job);
3339
TEST_EQ_STR (job->author, "foo");
3340
TEST_EQ_STR ((job->emits)[0], "hello");
3341
TEST_NE_P (job->start_on, NULL);
3342
TEST_EQ_P (job->env, NULL);
3346
TEST_EQ (rmdir (dirname), 0);
3349
TEST_FEATURE ("create both conf+override files, watch, then modify/delete conf");
3350
TEST_ENSURE_CLEAN_ENV ();
3351
TEST_FILENAME (dirname);
3352
TEST_EQ (mkdir (dirname, 0755), 0);
3355
strcpy (filename, dirname);
3356
strcat (filename, "/foo.conf");
3357
f = fopen (filename, "w");
3358
TEST_NE_P (f, NULL);
3359
fprintf (f, "start on started\n");
3360
fprintf (f, "author \"me\"\n");
3361
fprintf (f, "env foo=bar\n");
3362
fprintf (f, "emits hello\n");
3365
/* create override */
3366
strcpy (override, dirname);
3367
strcat (override, "/foo.override");
3368
f = fopen (override, "w");
3369
TEST_NE_P (f, NULL);
3370
fprintf (f, "manual\n");
3371
fprintf (f, "author \"you\"\n");
3375
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3376
TEST_NE_P (source, NULL);
3377
ret = conf_source_reload (source);
3380
TEST_FORCE_WATCH_UPDATE();
3382
/* ensure conf loaded */
3383
TEST_HASH_NOT_EMPTY (source->files);
3384
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3385
TEST_NE_P (file, NULL);
3386
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3387
TEST_NE_P (job, NULL);
3388
TEST_EQ_P (file->job, job);
3389
TEST_EQ_STR ((job->emits)[0], "hello");
3390
TEST_EQ_STR (job->author, "you");
3391
TEST_EQ_P (job->start_on, NULL);
3392
TEST_EQ_STR ((job->env)[0], "foo=bar");
3393
TEST_EQ_P (job->export, NULL);
3396
f = fopen (filename, "a");
3397
TEST_NE_P (f, NULL);
3398
fprintf (f, "export foo\n");
3401
TEST_FORCE_WATCH_UPDATE();
3403
/* ensure conf updated */
3404
TEST_HASH_NOT_EMPTY (source->files);
3405
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3406
TEST_NE_P (file, NULL);
3407
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3408
TEST_NE_P (job, NULL);
3409
TEST_EQ_STR ((job->env)[0], "foo=bar");
3410
TEST_NE_P (job->export, NULL);
3411
TEST_EQ_STR ((job->export)[0], "foo");
3416
TEST_FORCE_WATCH_UPDATE();
3418
/* ensure conf object deleted */
3419
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3420
TEST_EQ_P (file, NULL);
3421
TEST_HASH_EMPTY (source->files);
3422
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3423
TEST_EQ_P (job, NULL);
3424
file = (ConfFile *)nih_hash_lookup (source->files, override);
3425
TEST_EQ_P (file, NULL);
3429
TEST_EQ (rmdir (dirname), 0);
3431
TEST_FEATURE ("create both conf+override files, watch, then modify/delete override");
3432
TEST_ENSURE_CLEAN_ENV ();
3433
TEST_FILENAME (dirname);
3434
TEST_EQ (mkdir (dirname, 0755), 0);
3437
strcpy (filename, dirname);
3438
strcat (filename, "/foo.conf");
3439
f = fopen (filename, "w");
3440
TEST_NE_P (f, NULL);
3441
fprintf (f, "start on started\n");
3442
fprintf (f, "author \"me\"\n");
3443
fprintf (f, "env foo=bar\n");
3444
fprintf (f, "emits hello\n");
3447
/* create override */
3448
strcpy (override, dirname);
3449
strcat (override, "/foo.override");
3450
f = fopen (override, "w");
3451
TEST_NE_P (f, NULL);
3452
fprintf (f, "manual\n");
3453
fprintf (f, "author \"you\"\n");
3457
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3458
TEST_NE_P (source, NULL);
3459
ret = conf_source_reload (source);
3462
TEST_FORCE_WATCH_UPDATE();
3464
/* ensure conf loaded */
3465
TEST_HASH_NOT_EMPTY (source->files);
3466
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3467
TEST_NE_P (file, NULL);
3468
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3469
TEST_NE_P (job, NULL);
3470
TEST_EQ_P (file->job, job);
3471
TEST_EQ_STR ((job->emits)[0], "hello");
3472
TEST_EQ_STR (job->author, "you");
3473
TEST_EQ_P (job->start_on, NULL);
3474
TEST_EQ_STR ((job->env)[0], "foo=bar");
3475
TEST_EQ_P (job->export, NULL);
3477
/* modify override */
3478
f = fopen (override, "w");
3479
TEST_NE_P (f, NULL);
3480
fprintf (f, "description \"hello world\"\n");
3481
fprintf (f, "author \"ubuntu\"\n");
3484
TEST_FORCE_WATCH_UPDATE();
3486
/* ensure conf updated */
3487
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3488
TEST_NE_P (file, NULL);
3489
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3490
TEST_NE_P (job, NULL);
3491
TEST_EQ_P (file->job, job);
3492
TEST_EQ_STR (job->author, "ubuntu");
3493
TEST_NE_P (job->description, NULL);
3494
TEST_EQ_STR (job->description, "hello world");
3495
TEST_EQ_STR ((job->emits)[0], "hello");
3496
TEST_NE_P (job->start_on, NULL);
3498
/* delete override */
3501
TEST_FORCE_WATCH_UPDATE();
3503
/* ensure conf updated */
3504
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3505
TEST_NE_P (file, NULL);
3506
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3507
TEST_NE_P (job, NULL);
3508
TEST_EQ_P (file->job, job);
3509
TEST_NE_P (job->start_on, NULL);
3510
TEST_EQ_STR ((job->env)[0], "foo=bar");
3511
TEST_EQ_STR ((job->emits)[0], "hello");
3512
TEST_EQ_STR (job->author, "me");
3513
TEST_EQ_P (job->description, NULL);
3517
TEST_EQ (rmdir (dirname), 0);
3520
TEST_FEATURE ("create conf, watch, then create invalid override, delete override");
3521
TEST_ENSURE_CLEAN_ENV ();
3522
TEST_FILENAME (dirname);
3523
TEST_EQ (mkdir (dirname, 0755), 0);
3526
strcpy (filename, dirname);
3527
strcat (filename, "/foo.conf");
3528
f = fopen (filename, "w");
3529
TEST_NE_P (f, NULL);
3530
fprintf (f, "start on started\n");
3531
fprintf (f, "author \"wibble\"\n");
3532
fprintf (f, "emits hello\n");
3536
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3537
TEST_NE_P (source, NULL);
3538
ret = conf_source_reload (source);
3541
TEST_FORCE_WATCH_UPDATE();
3543
/* ensure conf loaded */
3544
TEST_HASH_NOT_EMPTY (source->files);
3545
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3546
TEST_NE_P (file, NULL);
3547
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3548
TEST_NE_P (job, NULL);
3549
TEST_EQ_P (file->job, job);
3550
TEST_EQ_STR ((job->emits)[0], "hello");
3551
TEST_NE_P (job->start_on, NULL);
3553
/* create (partially) invalid override (which should be
3556
strcpy (override, dirname);
3557
strcat (override, "/foo.override");
3558
f = fopen (override, "w");
3559
TEST_NE_P (f, NULL);
3560
fprintf (f, "manual\n");
3561
fprintf (f, "bleaugh!\n");
3562
fprintf (f, "wha...?\n");
3563
fprintf (f, "author \"moo\"\n");
3566
TEST_FORCE_WATCH_UPDATE();
3570
TEST_FORCE_WATCH_UPDATE();
3572
/* ensure conf still loaded */
3573
TEST_HASH_NOT_EMPTY (source->files);
3574
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3575
TEST_NE_P (file, NULL);
3576
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3577
TEST_NE_P (job, NULL);
3578
TEST_EQ_P (file->job, job);
3579
TEST_EQ_STR ((job->emits)[0], "hello");
3580
TEST_NE_P (job->start_on, NULL);
3581
TEST_EQ_STR (job->author, "wibble");
3585
TEST_EQ (rmdir (dirname), 0);
3587
TEST_FEATURE ("ensure override ignored for CONF_FILE");
3588
TEST_ENSURE_CLEAN_ENV ();
3589
TEST_FILENAME (dirname);
3590
TEST_EQ (mkdir (dirname, 0755), 0);
3592
/* create empty conf */
3593
strcpy (filename, dirname);
3594
strcat (filename, "/init.conf");
3595
f = fopen (filename, "w");
3596
TEST_NE_P (f, NULL);
3600
source = conf_source_new (NULL, dirname, CONF_FILE);
3601
TEST_NE_P (source, NULL);
3602
ret = conf_source_reload (source);
3604
/* We expect conf_source_reload to fail in this situation since
3605
* although "init.conf" is a supported config file, it is not
3606
* allowed to contain any stanzas, implying that it can only
3607
* contain comments. In fact, if the file exists but is zero
3608
* size that is currently an error since upstart blindly calls
3609
* nih_file_read(), which will fail since there are no bytes to
3613
err = nih_error_steal ();
3614
TEST_EQ (err->number, EILSEQ);
3617
TEST_FORCE_WATCH_UPDATE();
3619
/* ensure conf NOT loaded */
3620
TEST_HASH_EMPTY (source->files);
3622
/* create override */
3623
strcpy (override, dirname);
3624
strcat (override, "/init.override");
3625
f = fopen (override, "w");
3626
TEST_NE_P (f, NULL);
3627
fprintf (f, "manual\n");
3630
TEST_FORCE_WATCH_UPDATE();
3632
/* ensure conf still NOT loaded */
3633
TEST_HASH_EMPTY (source->files);
3638
TEST_EQ (rmdir (dirname), 0);
3640
/* Consume all available inotify instances so that the following
3641
* tests run without inotify.
3643
for (i = 0; i < 4096; i++)
3644
if ((fd[i] = inotify_init ()) < 0)
3648
/* If you don't have inotify, any override file must exist
3649
* before the system boots.
3652
TEST_FEATURE ("both conf+override files with no inotify support");
3653
TEST_ENSURE_CLEAN_ENV ();
3654
TEST_FILENAME (dirname);
3655
TEST_EQ (mkdir (dirname, 0755), 0);
3658
strcpy (filename, dirname);
3659
strcat (filename, "/foo.conf");
3660
f = fopen (filename, "w");
3661
TEST_NE_P (f, NULL);
3662
fprintf (f, "start on started\n");
3663
fprintf (f, "author \"me\"\n");
3664
fprintf (f, "env foo=bar\n");
3665
fprintf (f, "emits hello\n");
3668
/* create override */
3669
strcpy (override, dirname);
3670
strcat (override, "/foo.override");
3671
f = fopen (override, "w");
3672
TEST_NE_P (f, NULL);
3673
fprintf (f, "manual\n");
3674
fprintf (f, "author \"you\"\n");
3678
source = conf_source_new (NULL, dirname, CONF_JOB_DIR);
3679
TEST_NE_P (source, NULL);
3680
ret = conf_source_reload (source);
3683
/* ensure conf loaded */
3684
TEST_HASH_NOT_EMPTY (source->files);
3685
file = (ConfFile *)nih_hash_lookup (source->files, filename);
3686
TEST_NE_P (file, NULL);
3687
job = (JobClass *)nih_hash_lookup (job_classes, "foo");
3688
TEST_NE_P (job, NULL);
3689
TEST_EQ_P (file->job, job);
3690
TEST_EQ_STR ((job->emits)[0], "hello");
3691
TEST_EQ_STR (job->author, "you");
3692
TEST_EQ_P (job->start_on, NULL);
3693
TEST_EQ_STR ((job->env)[0], "foo=bar");
3694
TEST_EQ_P (job->export, NULL);
3699
TEST_EQ (rmdir (dirname), 0);
3702
nih_log_set_priority (NIH_LOG_MESSAGE);
3704
/* Release consumed instances */
3705
for (i = 0; i < 4096; i++) {
2421
3714
test_source_reload_file (void)